JBoss Community Archive (Read Only)

Savara

Define Information Model

One of the stages within the architecture phase is to define the information model for the message types associated with the messages exchanges between the interacting participants.

This involves defining message schema for each example message. The schema could already exist and be reused, it could be based on existing schema and just need to be upgraded to support new requirements, or it may need to be defined from scratch.

An example of a schema associated with the purchasing model is the store.xsd shown here:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.jboss.org/examples/store" xmlns:tns="http://www.jboss.org/examples/store" elementFormDefault="qualified">

    <element name="BuyRequest" type="tns:BuyRequestType"></element>
    <element name="BuyConfirmed" type="tns:BuyConfirmedType"></element>
    <element name="AccountNotFound" type="tns:AccountNotFoundType"></element>
    <element name="BuyFailed" type="tns:BuyFailedType"></element>

    <complexType name="BuyRequestType">
        <attribute name="id" type="string"></attribute>
        <attribute name="product" type="string"></attribute>
        <attribute name="customer" type="string"></attribute>
    </complexType>

    <complexType name="BuyConfirmedType">
        <attribute name="id" type="string"></attribute>
        <attribute name="amount" type="integer"></attribute>
        <attribute name="deliveryDate" type="date"></attribute>
    </complexType>
    
    <complexType name="AccountNotFoundType">
        <attribute name="id" type="string"></attribute>
        <attribute name="reason" type="string"></attribute>
    </complexType>
    
    <complexType name="BuyFailedType">
        <attribute name="id" type="string"></attribute>
        <attribute name="reason" type="string"></attribute>
    </complexType>
</schema>

Once the schema has been defined, then the example messages need to be updated to reference the schema, as shown in the following BuyRequest.xml example message:

<tns:BuyRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:tns="http://www.jboss.org/examples/store"
            xsi:schemaLocation="http://www.jboss.org/examples/store ../schema/store.xsd "
            id="1" product="Laptop" customer="Joe" />

Validating Example Messages against Schema

Once the association between example messages and the schema has been established, it is possible to validate the messages against the schema. Select the context menu associated with the XML file (e.g. BuyRequest.xml), and choose the Validate menu item. You should see the following message displayed, and no errors or warnings appear in the Problems or Markers view:

images/author/download/attachments/3735778/SchemaValidationResults .png

However, if we now introduce an error into this example message, for example change the attribute name 'customer' to 'customerX', and then perform the validation again, you will see an error has been reported:

images/author/download/attachments/3735778/SchemaValidationError.png

Don't forget to change the attribute name back to 'customer', and re-validate the XML file, before proceeding - as we will need the message be valid for the next section of the document.

For further information on how to use the validation capabilities within Eclipse, please read the Eclipse XML Validation Tutorial.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-13 09:36:26 UTC, last content change 2012-02-10 14:16:07 UTC.